home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / formats / imgfiles / imgfiles.spc
Text File  |  1980-02-06  |  10KB  |  347 lines

  1.  
  2.     Preview:  A sample color-mapped image file
  3.     ------------------------------------------
  4.  
  5.   Block
  6.  
  7.     -------------------
  8.    1    | "SCMI" | "   1" |    <---  File Identification
  9.     -------------------
  10.     ---------------------
  11.    2A    | "AT" | "      50" |    <---  Section header (attributes)
  12.     ---------------------
  13.     -----------------------------------------------------------------------
  14.    2B    | " 512" | " 464" | " 128" | "GDA 1 222.21 (-114.5 54.8) (17.2 84.0)" |
  15.     -----------------------------------------------------------------------
  16.     ---------------------                        |
  17.    3A    | "CM" | "     384" |    <---  Section header (color map)    |
  18.     ---------------------                       Attributes:
  19.     -------------                        width, height,
  20.    3B    | b | b | b |  <---  Color map, color[0]        # colors,
  21.     -------------                        associated data
  22.     | b | b | b |  <---  color[1]
  23.     -------------
  24.          ...                ['b' => 8-bit byte]
  25.     -------------
  26.     | b | b | b |  <---  color[n-1]
  27.     -------------
  28.     ---------------------
  29.    4A    | "PD" | "  237568" |    <---  Section header (pixel data)
  30.     ---------------------
  31.     ---------------------
  32.    4B    | bbbbb... ...bbbbb |  <--- Pixel data
  33.     ---------------------
  34.  
  35.  
  36.  
  37.     Sample associated data in attributes:
  38.  
  39.     "GDA 1 222.21 (-114.5 54.8) (17.2 84.0)"
  40.       \   \    \         \           \
  41.        \   \    \         \         Longitute/Latitude @ top right
  42.         \   \    \         --- Longitude/Latitude @ bottom left
  43.          \   \    ---  Scale, pixels per radian of longitude
  44.           \   --- Version # of application data format
  45.            ---  Application identification
  46.  
  47.  
  48.  
  49.  
  50.             "Img" Image File Formats
  51.  
  52.  
  53.     This is the beginning of a larger specification document
  54.     for an overall subsystem to handle simple image processing.
  55.     The subsystem is tentatively named "Img".  This document
  56.     includes only these specification sections:
  57.  
  58.  
  59.     1  Img File Formats
  60.  
  61.     1.1  Color Mapped Images
  62.     1.2  24-bit RGB Images
  63.  
  64.  
  65.     Additional sections have not been written, but would describe
  66.     the imglib routines and the set of programs which manipulate
  67.     images in this format.  Most of this information can be extracted
  68.     from source modules by using the ccomex comment extractor.
  69.  
  70.     As with the file format, imglib functions were designed
  71.     to make the interface from application code as simple as possible.
  72.     Most of imglib is independent of the underlying graphics or
  73.     window system.  One module supplies such system-dependent
  74.     support for X11R3.
  75.  
  76.  
  77.  
  78. 1  Img File Formats
  79.  
  80. 1.1  Color Mapped Images
  81.  
  82.     Purposes of this particular file format are:
  83.  
  84.     1.  Represent color-mapped images which use no more than 256 colors.
  85.     2.  Conserve disk space.
  86.     3.  Conserve processing time for reading and displaying images.
  87.     4.  Minimize complexity in basic image manipulation functions.
  88.     5.  Allow extensibility in future versions.
  89.  
  90.  
  91.     The format defined here represents an uncompressed image file.
  92.     Such images would normally be stored in compressed format, as
  93.     used by the UNIX* compress/uncompress utility.  (* UNIX is
  94.     a trademark of AT&T.)  When this is true, the filename ends
  95.     with ".Z".
  96.  
  97.         One simple way to read compressed files is to pipe input
  98.         through uncompress, approximately as follows:
  99.  
  100.         if ( compressed )
  101.            {
  102.            sprintf ( command, "uncompress <%s", filename );
  103.            img_file = popen ( command,  "r" );
  104.            }
  105.         else
  106.            img_file = fopen ( filename, "r" );
  107.  
  108.     In addition to easy availability of compress/uncompress,
  109.     use of this particular compress tool set generally produces
  110.     better compression than run length encoding.  It also improves
  111.     on storage of bitmaps:  Using one bit per byte in compressed
  112.     format usually produces better compression than packing 8 bits
  113.     per byte.
  114.  
  115.  
  116.  
  117.     Some design rules applied to all parts of this file format
  118.     are:
  119.  
  120.     1.  All data is a byte stream:  The format has no dependence
  121.         on byte or word order for any particular machine.
  122.  
  123.     2.  Pixel data, which are indices to the color map, and RGB
  124.         component values are 8-bit unsigned binary values.
  125.  
  126.     3.  Attribute data, except RGB values in the color map, are
  127.         stored in fixed-size ascii fields.  Integers use either
  128.         4-byte or 8-byte fields; programs can read or write them
  129.         via scanf/printf functions using, for example, "%4u" or
  130.         "%4i" format.
  131.  
  132.     4.  Whenever the length of a section of the file may vary
  133.         depending on image contents, that section is preceded
  134.         by a prefix which identifies it and gives its length
  135.         in bytes.  This facilitates use of block-oriented i/o
  136.         operations to optimize i/o speed; it does this in a
  137.         way which allows future extension of the image format
  138.         to include sections whose size does not depend on data
  139.         in the attribute section.
  140.  
  141.  
  142.  
  143. 1.1.1    Top Level Structure
  144.  
  145.     A color-mapped image file contains the following blocks:
  146.  
  147.     1.   File identification
  148.     2A.  Attribute prefix
  149.     2B.  Attributes
  150.     3A.  Color map prefix
  151.     3B.  Color map
  152.     4A.  Pixel data prefix
  153.     4B.  Pixel data
  154.  
  155.  
  156.  
  157. 1.1.2  Section Prefixes
  158.  
  159.     Each "prefix" block identifies a section and report reports
  160.     its size.  Format:
  161.  
  162.           +0      +2
  163.         -----------------
  164.         | xx | nnnnnnnn |
  165.         -----------------
  166.            \       \___ Length of data in next section:  %8d or %8u
  167.             \
  168.              \___ Section identifier:    AT  =>  Attributes
  169.                         CM  =>  Color Map
  170.                         PD  =>  Pixel Data
  171.  
  172.     Other prefixes could be used to represent data sections
  173.     in formats defined outside this specification.
  174.  
  175.  
  176.  
  177. 1.1.2  File Identification
  178.  
  179.     This identifies the file type and the version number of the
  180.     file format.
  181.  
  182.            +0      +4
  183.         ---------------
  184.         | SCMI | nnnn |
  185.         ---------------
  186.             \       \___ File format version #:  %4d or %4u
  187.              \
  188.               \___ File type code:  "SCMI"
  189.  
  190.  
  191.  
  192. 1.1.3  Attributes
  193.  
  194.     The "attributes" section defines image characteristics other
  195.     than the content of its color map.  This consists of the image
  196.     width and height, number of colors, and associated data for
  197.     application use.  For purposes of this file format, associated
  198.     data is only a sequence of bytes.
  199.  
  200.     An appropriate convention for higher level specifications
  201.     would be to begin any associated data with an application code
  202.     and version number to identify its format.
  203.  
  204.         -----------------
  205.         | AT | nnnnnnnn |  <---  Section header
  206.         -----------------
  207.  
  208.            +0      +4     +8    +12
  209.         ---------------------------------------------
  210.         | nnnn | nnnn | nnnn | [... assoc data ...] |
  211.         ---------------------------------------------
  212.             \       \      \        \__Associated data, if any
  213.              \        \       \__Number of colors:  %4d or %4u
  214.               \         \__Height, pixels:  %4d or %4u
  215.                \__Width%4d or %4u
  216.  
  217.  
  218.         Size of associated data is block size - 12 bytes.
  219.         (Block size from section header)
  220.  
  221.  
  222. 1.1.4  Color Map
  223.  
  224.     The color map is an array with one entry for each color
  225.     in the image.  For grey-scale images, each RGB component
  226.     is identical.  Black-and-white images have a two-entry
  227.     color table.
  228.  
  229.  
  230.         -----------------
  231.         | CM | nnnnnnnn |  <---  Section header
  232.         -----------------
  233.  
  234.           Red  Grn Blue
  235.            /   /   /
  236.         -------------
  237.         | b | b | b |  <---  color[0]    @ +0
  238.         -------------
  239.         | b | b | b |  <---  color[1]    @ +3
  240.         -------------
  241.              ...
  242.         -------------
  243.         | b | b | b |  <---  color[k]    @ +3*k
  244.         -------------
  245.              ...
  246.         -------------
  247.         | b | b | b |  <---  color[n-1]    @ +3*(n-1)
  248.         -------------
  249.  
  250.  
  251.     Each color component byte (b) is an unsigned 8-bit integer.
  252.  
  253.     Block size is 3*n, where n is the number of colors defined
  254.     in the attributes.
  255.  
  256.  
  257. 1.1.5  Pixel Data
  258.  
  259.     Pixel data is an array with one 8-bit entry for each pixel.
  260.     Pixels are in conventional scan line order.
  261.  
  262.  
  263.         -----------------
  264.         | CM | nnnnnnnn |  <---  Section header
  265.         -----------------
  266.  
  267.         ---------------------
  268.         | bbbbb... ...bbbbb |  <--- Pixel data
  269.         ---------------------
  270.  
  271.     Each pixel value byte (b) is an 8-bit unsigned integer which
  272.     is the index of a color map entry.  Valid range is [0,n-1],
  273.     where n is the number of colors defined in the attributes.
  274.  
  275.     Size of the pixel data section is width*height bytes.
  276.  
  277.     Order of pixels is row major -- Top to bottom by rows,
  278.     left to right within each row.
  279.  
  280.  
  281.  
  282. 1.2  24-bit RGB Images
  283.  
  284.     Purposes of this particular file format are:
  285.  
  286.     1.  Represent images using 24 bits per pixel:  8 bits each
  287.         for red, green, and blue values.
  288.     2.  Conserve disk space.
  289.     3.  Maintain reasonable consistency with existing techniques
  290.         for acquiring RGB image data
  291.     4.  Minimize complexity in basic image manipulation function.
  292.     5.  Allow using an ordinary text editor to define image attributes.
  293.  
  294.  
  295.     As with color mapped images, 24-bit RGB images can optionally
  296.     be stored in compressed format.  Any file which is compressed
  297.     has ".Z" appended to its filename.
  298.  
  299.  
  300. 1.2.1    Top Level Structure
  301.  
  302.     A 24-bit RGB image is defined by four separate files which
  303.     are identified by file naming conventions:
  304.  
  305.     1.  Attributes:        <name>.a[.Z]
  306.     2.  Red component:    <name>.r[.Z]
  307.     3.  Green component:    <name>.g[.Z]
  308.     4.  Blue component:    <name>.b[.Z]
  309.  
  310.     For any given image, the various component files may be
  311.     either compressed or uncompressed on an individual basis.
  312.  
  313.  
  314. 1.2.2  Attribute File
  315.  
  316.     The attribute file contains precisely the data which would
  317.     appear in the attribute section (section 2B) of a color-mapped
  318.     image file, except that the color count is meaningless:
  319.  
  320.            +0      +4     +8    +12
  321.         ---------------------------------------------
  322.         | nnnn | nnnn | xxxx | [... assoc data ...] |
  323.         ---------------------------------------------
  324.             \       \      \        \__Associated data, if any
  325.              \        \       \__Reserved for color count, 4 chars
  326.               \         \__Height, pixels:  %4d or %4u
  327.                \__Width%4d or %4u
  328.  
  329.  
  330.     Size of associated data is the file size - 12.
  331.  
  332.     Although attribute files can be stored in compressed format,
  333.     keeping them in easily editable uncompressed format can
  334.     simplify generating and maintaining image data bases.
  335.  
  336.  
  337. 1.2.3  RGB Component Files
  338.  
  339.     Each RGB component file contains 8-bit unsigned pixel values
  340.     for the red, green, or blue component of the image.
  341.  
  342.     Each file represents width*height bytes, where width and height
  343.     are defined in the corresponding attribute file.
  344.  
  345.     Order of pixels is row major -- Top to bottom by rows,
  346.     left to right within each row.
  347.